package cn.gson.crm.controller.potential;

import java.util.List;
import java.util.Map;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.EmploDao;

/**
 * 实现ajax的数据传递
 */
@WebServlet("/ajax/data")
public class AjaxData extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private EmploDao empDao = new EmploDao();
     
	@Override
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		System.out.println(id+" id");
		List<Map<String, Object>> data =  empDao.emploGetDeptId(Integer.parseInt(id));
		if(id==null){
			request.setAttribute("empList", data);
			forward("student/student_show");
		}else{ 
			response.setContentType("application/json;charset=utf-8");
			//把结果转换成JSON字符串
			String jsonStr = JSONArray.toJSONString(data);
			//输出结果
			response.getWriter().append(jsonStr);
		}
	}
}
